<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Inbox</title>
    </h:head>
    <h:body>
        <h:form id="headerbar" style="width: 100%">
            <p:panelGrid columns="6" style="margin: 0 auto;">
                <p:column>
                    <h:outputText value="Welcome, #{calendarBean.loggedUser.name}!"/>
                </p:column>
                <p:column>
                    <p:commandLink  value="MeteoCal" action="calendar" ajax="false" />
                </p:column>
                <p:column>
                    <p:outputLabel for="email" value="Search User by Email:"/>
                    <p:inputText id="email" value="#{calendarBean.calendarOwner.email}"/>
                    <p:commandButton value="Search" action="#{calendarBean.search(calendarBean.calendarOwner.email)}" ajax="false"/>
                </p:column>
                <p:column>
                    <p:commandButton  value="Check Inbox (#{inbox.getInboxSize()})" action="viewinbox" ajax="false" />
                </p:column>
                <p:column>
                    <p:commandButton value="Account settings" type="button" onclick="PF('dialog').show();" />
                    <p:dialog header="Modal Dialog" widgetVar="dialog" modal="true">
                        <h:outputText value="Choose your calendar's privacy:" />
                        <p:commandButton value="Public" icon="ui-icon-check" action="#{userBean.setPublic()}" ajax="false"/>
                        <p:commandButton value="Private"  icon="ui-icon-close" action="#{userBean.setPrivate()}" ajax="false"/>
                    </p:dialog>                
                </p:column>
                <p:column>
                    <p:commandButton action="#{loginBean.logout()}" value="logout"/>
                </p:column>
            </p:panelGrid>
        </h:form>
        <h:form id="inboxform">
            <h3>Inbox</h3>
            <p:tabView id="t">
                <p:tab title="Invitations (#{inbox.onInvitationlist.size()})">
                    <p:dataTable id="inbox" value="#{inbox.myEventlist}" var="events" selection="#{inbox.selectedEvent}" rowKey="#{events.id}">
                        <f:facet name="header">
                            Event List
                        </f:facet>
                        <p:column selectionMode="single"/>
                        <p:column headerText="Name">
                            <h:outputText value="#{events.name}" />
                        </p:column>
                        <p:column headerText="Description">
                            <h:outputText value="#{events.description}" />
                        </p:column>
                        <p:column headerText="From">
                            <h:outputText value="#{events.startdate}">
                                <f:convertDateTime pattern="yyyy-MM-dd HH:mm" timeZone="GMT+1"/>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="To">
                            <h:outputText value="#{events.enddate}" >
                                <f:convertDateTime pattern="yyyy-MM-dd HH:mm" timeZone="GMT+1"/>
                            </h:outputText>                        
                        </p:column>
                        <p:column headerText="OutDoor/Indoor">
                            <h:outputText value="#{events.outdoor}" />
                        </p:column>
                        <p:column headerText="Public">
                            <h:outputText value="#{events.privacy}" />
                        </p:column>                    
                        <p:column headerText="City">
                            <h:outputText value="#{events.city}" />
                        </p:column>
                        <p:column headerText="Address">
                            <h:outputText value="#{events.address}" />
                        </p:column>                
                        <p:column headerText="Organizer">
                            <h:outputText value="#{events.organizer}" />
                        </p:column>
                    </p:dataTable>
                    <h3> </h3>
                    <p:commandButton action="#{inbox.buttonAction}" update="invitationlist" value="See Details"/>
                    <p:dataTable value="#{inbox.userlist}" var="user" id="invitationlist">
                        <f:facet name="header">
                            Invitation List
                        </f:facet>
                        <p:column headerText="Name">
                            <h:outputText value="#{user.name}" />
                        </p:column>
                        <p:column headerText="Email">
                            <h:outputText value="#{user.email}" />
                        </p:column>
                    </p:dataTable>
                    <p:commandButton action="#{inbox.accept}" value="Accept" update="@all" />
                    <p:commandButton action="#{inbox.decline}" value="Decline" update="@all"/>
                    <p:commandButton action="calendar" value="Go Back" />
                </p:tab>
                <p:tab title="Notifications (#{notificationBean.myNotificationlist.size()})">
                    <p:dataTable id="notificationlist" value="#{notificationBean.myNotificationlist}" selection="#{notificationBean.myNotification}" var="mynotification" rowKey="#{mynotification.notificationId}" >
                        <f:facet name="header">
                            Notification List
                        </f:facet>
                        <p:column selectionMode="single" />
                        <p:column headerText="Name">
                            <h:outputText value="#{mynotification.eventName}" />
                        </p:column>
                        <p:column headerText="Description">
                            <h:outputText value="#{mynotification.eventDescription}" />
                        </p:column>
                        <p:column headerText="From">
                            <h:outputText value="#{mynotification.eventStartdate}">
                                <f:convertDateTime pattern="yyyy-MM-dd HH:mm" timeZone="GMT+1"/>
                            </h:outputText>   
                        </p:column>
                        <p:column headerText="To">
                            <h:outputText value="#{mynotification.eventEnddate}">
                                <f:convertDateTime pattern="yyyy-MM-dd HH:mm" timeZone="GMT+1"/>
                            </h:outputText> 
                        </p:column>
                        <p:column headerText="City">
                            <h:outputText value="#{mynotification.eventCity}" />
                        </p:column>
                        <p:column headerText="Address">
                            <h:outputText value="#{mynotification.eventAddress}" />
                        </p:column>
                        <p:column headerText="Message">
                            <h:outputText value="#{mynotification.message}" />
                        </p:column>
                        <p:column headerText="Suggested Day">
                            <h:outputText value="#{mynotification.suggestedDay}">
                                <f:convertDateTime pattern="yyyy-MM-dd HH:mm" timeZone="GMT+1"/>
                            </h:outputText> 
                        </p:column>
                    </p:dataTable>
                    <p:commandButton action="#{notificationBean.setAsReadNotification()}" value="Set as read" update="@all"/>
                    <p:commandButton action="calendar" value="Go Back"/>
                </p:tab>
            </p:tabView>
        </h:form>
    </h:body>
</html>
